#ifndef __ANALYSIS__
#define __ANALYSIS__ 1

#include "TFile.h"
#include "TH1F.h"
#include "TTree.h"
#include "TVector.h"
#include "RawData.hh"
#include "HeaderParameters.hh"
#include <string>

using std::string;

class Analysis {

public:

  Analysis(string rootfilename, HeaderParameters* header_arg, RawData* my_data_arg, float voltthreshold, float varthreshold, int channels);
  ~Analysis();

  void charge_minmax();
  void charge_range();
  void charge_histo(bool writewaveform);
  void write_charge_histo();

  void noise_minmax();
  void noise_range();
  void noise_histo();
  void write_noise_histo();

  void variance_minmax();
  void variance_range();
  void variance_histo();
  void write_variance_histo();

  bool variance_cut(bool first_loop);
  void write_variance_cut();

  bool count_peaks(bool first_loop_peakcount);
  void write_count_peaks();

  void filltree();
  void WriteRootfile();
  void PlantTree();

private:


  HeaderParameters * header;

  TFile* rootfile;
  TTree* tree;

  //----charge_histo----//
  float charge[100];
  float num_electrons;
  float min_num_electrons[2];
  float max_num_electrons[2];
  float total_num_electrons[2];
  float mean_num_electrons;
  bool* all_electrons_cut;
  int num_neg;
  bool first_trace_charge;
  float num_electrons_threshold;
  int num_electrons_outside;
  TH1F** trace_electrons;
  TH1F* total_trace_electrons;
  float max_total_electrons;
  //--------------------//

  //-----noise_histo----//
  bool first_sample_noise;
  float voltage;
  float max_v_noise;
  float min_v_noise;
  float total_v_noise;
  float mean_v_noise;
  int num_over;
  //--------------------//

  //---variance_histo---//
  bool first_trace_variance;
  float v_total;
  float v_mean;
  float v_diff_total;
  float sigma_squared;
  float sigma;
  float max_sigma;
  float min_sigma;
  float total_sigma;
  float mean_sigma;
  TH1F** variance;
  //--------------------//

  //----count_peaks-----//
  float trace_vmax[100];
  int num_peaks;
  int num_non_empty[100];
  //--------------------//

  //----general_use-----//
	int my_channels;
  float voltage_threshold;
  float variance_threshold;
  float time_per_div;
  int num_bins;
  int num_traces;
  int num_traces_cut;
  RawData* my_data;
  TH1F** voltage_noise;
	TH1F** voltage_maxnoise; 
 TH1F** my_waveforms;
  //--------------------//

  float Qpeak;
  float Qall;

 // void ClearRootVariables();


};


#endif
